package org.example.view.console;

import org.dom4j.DocumentException;
import org.example.entity.Admin;
import org.example.service.AdminService;
import org.example.service.IAdminService;
import org.example.view.console.CinemaView;

import java.io.IOException;
import java.text.ParseException;
import java.util.Scanner;

/**
 * @author TonySong
 * @date 2025/7/28 0028
 * @time 16:42
 */
public class View {

    public static void main(String[] args) throws IOException, ClassNotFoundException, DocumentException, ParseException {
        Scanner scanner=new Scanner(System.in);
        CinemaView cinemaView =new CinemaView();
        AdminService adminService=new AdminService();
        if(IAdminService.file.exists()){
            Admin admin = adminService.init();
            adminService.setAdmin(admin);
            cinemaView.menu(admin);
        }else{
            System.out.println("请输入账号：");
            String username=scanner.next();
            System.out.println("请输入密码：");
            String password=scanner.next();
            Admin login = adminService.login(username, password);
            if(login!=null){
                adminService.setAdmin(login);
                cinemaView.menu(login);
            }else{
                System.out.println("账号或密码错误！");
            }
        }


    }
}
